<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />

<meta name="author" content="Brian B. Avants, Arman Eshaghi" />

<meta name="date" content="2015-03-25" />

<title>iMath (mathematical operations inside ANTsR)</title>



<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; }
code > span.dt { color: #902000; }
code > span.dv { color: #40a070; }
code > span.bn { color: #40a070; }
code > span.fl { color: #40a070; }
code > span.ch { color: #4070a0; }
code > span.st { color: #4070a0; }
code > span.co { color: #60a0b0; font-style: italic; }
code > span.ot { color: #007020; }
code > span.al { color: #ff0000; font-weight: bold; }
code > span.fu { color: #06287e; }
code > span.er { color: #ff0000; font-weight: bold; }
</style>
<style type="text/css">
  pre:not([class]) {
    background-color: white;
  }
</style>


<link href="data:text/css,body%20%7B%0A%20%20background%2Dcolor%3A%20%23fff%3B%0A%20%20margin%3A%201em%20auto%3B%0A%20%20max%2Dwidth%3A%20700px%3B%0A%20%20overflow%3A%20visible%3B%0A%20%20padding%2Dleft%3A%202em%3B%0A%20%20padding%2Dright%3A%202em%3B%0A%20%20font%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0A%20%20font%2Dsize%3A%2014px%3B%0A%20%20line%2Dheight%3A%201%2E35%3B%0A%7D%0A%0A%23header%20%7B%0A%20%20text%2Dalign%3A%20center%3B%0A%7D%0A%0A%23TOC%20%7B%0A%20%20clear%3A%20both%3B%0A%20%20margin%3A%200%200%2010px%2010px%3B%0A%20%20padding%3A%204px%3B%0A%20%20width%3A%20400px%3B%0A%20%20border%3A%201px%20solid%20%23CCCCCC%3B%0A%20%20border%2Dradius%3A%205px%3B%0A%0A%20%20background%2Dcolor%3A%20%23f6f6f6%3B%0A%20%20font%2Dsize%3A%2013px%3B%0A%20%20line%2Dheight%3A%201%2E3%3B%0A%7D%0A%20%20%23TOC%20%2Etoctitle%20%7B%0A%20%20%20%20font%2Dweight%3A%20bold%3B%0A%20%20%20%20font%2Dsize%3A%2015px%3B%0A%20%20%20%20margin%2Dleft%3A%205px%3B%0A%20%20%7D%0A%0A%20%20%23TOC%20ul%20%7B%0A%20%20%20%20padding%2Dleft%3A%2040px%3B%0A%20%20%20%20margin%2Dleft%3A%20%2D1%2E5em%3B%0A%20%20%20%20margin%2Dtop%3A%205px%3B%0A%20%20%20%20margin%2Dbottom%3A%205px%3B%0A%20%20%7D%0A%20%20%23TOC%20ul%20ul%20%7B%0A%20%20%20%20margin%2Dleft%3A%20%2D2em%3B%0A%20%20%7D%0A%20%20%23TOC%20li%20%7B%0A%20%20%20%20line%2Dheight%3A%2016px%3B%0A%20%20%7D%0A%0Atable%20%7B%0A%20%20margin%3A%201em%20auto%3B%0A%20%20border%2Dwidth%3A%201px%3B%0A%20%20border%2Dcolor%3A%20%23DDDDDD%3B%0A%20%20border%2Dstyle%3A%20outset%3B%0A%20%20border%2Dcollapse%3A%20collapse%3B%0A%7D%0Atable%20th%20%7B%0A%20%20border%2Dwidth%3A%202px%3B%0A%20%20padding%3A%205px%3B%0A%20%20border%2Dstyle%3A%20inset%3B%0A%7D%0Atable%20td%20%7B%0A%20%20border%2Dwidth%3A%201px%3B%0A%20%20border%2Dstyle%3A%20inset%3B%0A%20%20line%2Dheight%3A%2018px%3B%0A%20%20padding%3A%205px%205px%3B%0A%7D%0Atable%2C%20table%20th%2C%20table%20td%20%7B%0A%20%20border%2Dleft%2Dstyle%3A%20none%3B%0A%20%20border%2Dright%2Dstyle%3A%20none%3B%0A%7D%0Atable%20thead%2C%20table%20tr%2Eeven%20%7B%0A%20%20background%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0A%0Ap%20%7B%0A%20%20margin%3A%200%2E5em%200%3B%0A%7D%0A%0Ablockquote%20%7B%0A%20%20background%2Dcolor%3A%20%23f6f6f6%3B%0A%20%20padding%3A%200%2E25em%200%2E75em%3B%0A%7D%0A%0Ahr%20%7B%0A%20%20border%2Dstyle%3A%20solid%3B%0A%20%20border%3A%20none%3B%0A%20%20border%2Dtop%3A%201px%20solid%20%23777%3B%0A%20%20margin%3A%2028px%200%3B%0A%7D%0A%0Adl%20%7B%0A%20%20margin%2Dleft%3A%200%3B%0A%7D%0A%20%20dl%20dd%20%7B%0A%20%20%20%20margin%2Dbottom%3A%2013px%3B%0A%20%20%20%20margin%2Dleft%3A%2013px%3B%0A%20%20%7D%0A%20%20dl%20dt%20%7B%0A%20%20%20%20font%2Dweight%3A%20bold%3B%0A%20%20%7D%0A%0Aul%20%7B%0A%20%20margin%2Dtop%3A%200%3B%0A%7D%0A%20%20ul%20li%20%7B%0A%20%20%20%20list%2Dstyle%3A%20circle%20outside%3B%0A%20%20%7D%0A%20%20ul%20ul%20%7B%0A%20%20%20%20margin%2Dbottom%3A%200%3B%0A%20%20%7D%0A%0Apre%2C%20code%20%7B%0A%20%20background%2Dcolor%3A%20%23f7f7f7%3B%0A%20%20border%2Dradius%3A%203px%3B%0A%20%20color%3A%20%23333%3B%0A%7D%0Apre%20%7B%0A%20%20white%2Dspace%3A%20pre%2Dwrap%3B%20%20%20%20%2F%2A%20Wrap%20long%20lines%20%2A%2F%0A%20%20border%2Dradius%3A%203px%3B%0A%20%20margin%3A%205px%200px%2010px%200px%3B%0A%20%20padding%3A%2010px%3B%0A%7D%0Apre%3Anot%28%5Bclass%5D%29%20%7B%0A%20%20background%2Dcolor%3A%20%23f7f7f7%3B%0A%7D%0A%0Acode%20%7B%0A%20%20font%2Dfamily%3A%20Consolas%2C%20Monaco%2C%20%27Courier%20New%27%2C%20monospace%3B%0A%20%20font%2Dsize%3A%2085%25%3B%0A%7D%0Ap%20%3E%20code%2C%20li%20%3E%20code%20%7B%0A%20%20padding%3A%202px%200px%3B%0A%7D%0A%0Adiv%2Efigure%20%7B%0A%20%20text%2Dalign%3A%20center%3B%0A%7D%0Aimg%20%7B%0A%20%20background%2Dcolor%3A%20%23FFFFFF%3B%0A%20%20padding%3A%202px%3B%0A%20%20border%3A%201px%20solid%20%23DDDDDD%3B%0A%20%20border%2Dradius%3A%203px%3B%0A%20%20border%3A%201px%20solid%20%23CCCCCC%3B%0A%20%20margin%3A%200%205px%3B%0A%7D%0A%0Ah1%20%7B%0A%20%20margin%2Dtop%3A%200%3B%0A%20%20font%2Dsize%3A%2035px%3B%0A%20%20line%2Dheight%3A%2040px%3B%0A%7D%0A%0Ah2%20%7B%0A%20%20border%2Dbottom%3A%204px%20solid%20%23f7f7f7%3B%0A%20%20padding%2Dtop%3A%2010px%3B%0A%20%20padding%2Dbottom%3A%202px%3B%0A%20%20font%2Dsize%3A%20145%25%3B%0A%7D%0A%0Ah3%20%7B%0A%20%20border%2Dbottom%3A%202px%20solid%20%23f7f7f7%3B%0A%20%20padding%2Dtop%3A%2010px%3B%0A%20%20font%2Dsize%3A%20120%25%3B%0A%7D%0A%0Ah4%20%7B%0A%20%20border%2Dbottom%3A%201px%20solid%20%23f7f7f7%3B%0A%20%20margin%2Dleft%3A%208px%3B%0A%20%20font%2Dsize%3A%20105%25%3B%0A%7D%0A%0Ah5%2C%20h6%20%7B%0A%20%20border%2Dbottom%3A%201px%20solid%20%23ccc%3B%0A%20%20font%2Dsize%3A%20105%25%3B%0A%7D%0A%0Aa%20%7B%0A%20%20color%3A%20%230033dd%3B%0A%20%20text%2Ddecoration%3A%20none%3B%0A%7D%0A%20%20a%3Ahover%20%7B%0A%20%20%20%20color%3A%20%236666ff%3B%20%7D%0A%20%20a%3Avisited%20%7B%0A%20%20%20%20color%3A%20%23800080%3B%20%7D%0A%20%20a%3Avisited%3Ahover%20%7B%0A%20%20%20%20color%3A%20%23BB00BB%3B%20%7D%0A%20%20a%5Bhref%5E%3D%22http%3A%22%5D%20%7B%0A%20%20%20%20text%2Ddecoration%3A%20underline%3B%20%7D%0A%20%20a%5Bhref%5E%3D%22https%3A%22%5D%20%7B%0A%20%20%20%20text%2Ddecoration%3A%20underline%3B%20%7D%0A%0A%2F%2A%20Class%20described%20in%20https%3A%2F%2Fbenjeffrey%2Ecom%2Fposts%2Fpandoc%2Dsyntax%2Dhighlighting%2Dcss%0A%20%20%20Colours%20from%20https%3A%2F%2Fgist%2Egithub%2Ecom%2Frobsimmons%2F1172277%20%2A%2F%0A%0Acode%20%3E%20span%2Ekw%20%7B%20color%3A%20%23555%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%2F%2A%20Keyword%20%2A%2F%0Acode%20%3E%20span%2Edt%20%7B%20color%3A%20%23902000%3B%20%7D%20%2F%2A%20DataType%20%2A%2F%0Acode%20%3E%20span%2Edv%20%7B%20color%3A%20%2340a070%3B%20%7D%20%2F%2A%20DecVal%20%28decimal%20values%29%20%2A%2F%0Acode%20%3E%20span%2Ebn%20%7B%20color%3A%20%23d14%3B%20%7D%20%2F%2A%20BaseN%20%2A%2F%0Acode%20%3E%20span%2Efl%20%7B%20color%3A%20%23d14%3B%20%7D%20%2F%2A%20Float%20%2A%2F%0Acode%20%3E%20span%2Ech%20%7B%20color%3A%20%23d14%3B%20%7D%20%2F%2A%20Char%20%2A%2F%0Acode%20%3E%20span%2Est%20%7B%20color%3A%20%23d14%3B%20%7D%20%2F%2A%20String%20%2A%2F%0Acode%20%3E%20span%2Eco%20%7B%20color%3A%20%23888888%3B%20font%2Dstyle%3A%20italic%3B%20%7D%20%2F%2A%20Comment%20%2A%2F%0Acode%20%3E%20span%2Eot%20%7B%20color%3A%20%23007020%3B%20%7D%20%2F%2A%20OtherToken%20%2A%2F%0Acode%20%3E%20span%2Eal%20%7B%20color%3A%20%23ff0000%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%2F%2A%20AlertToken%20%2A%2F%0Acode%20%3E%20span%2Efu%20%7B%20color%3A%20%23900%3B%20font%2Dweight%3A%20bold%3B%20%7D%20%2F%2A%20Function%20calls%20%2A%2F%20%0Acode%20%3E%20span%2Eer%20%7B%20color%3A%20%23a61717%3B%20background%2Dcolor%3A%20%23e3d2d2%3B%20%7D%20%2F%2A%20ErrorTok%20%2A%2F%0A%0A" rel="stylesheet" type="text/css" />

</head>

<body>



<div id="header">
<h1 class="title">iMath (mathematical operations inside ANTsR)</h1>
<h4 class="author"><em>Brian B. Avants, Arman Eshaghi</em></h4>
<h4 class="date"><em>2015-03-25</em></h4>
</div>


<div id="basic-operations" class="section level2">
<h2>Basic operations</h2>
<p><code>iMath</code> wraps some functions of <code>ImageMath</code> from <a href="http://stnava.github.io/ANTs/">ANTs software</a>. For basic arithmetics (e.g., add, subtract), while it’s possible to use <code>iMath</code>, usually it is easier to use <code>antsImage</code> class capabilities.</p>
<ul>
<li><p>Basic arithmetics with <code>antsImageClass</code> is easier, and is similar to array operations in R:</p>
<pre class="sourceCode r"><code class="sourceCode r">fi  &lt;-<span class="st"> </span><span class="kw">antsImageRead</span>(<span class="kw">getANTsRData</span>(<span class="st">&quot;r16&quot;</span>), <span class="dv">2</span>)
sumfi &lt;-<span class="st"> </span>fi +<span class="st"> </span>fi
mulfi &lt;-<span class="st"> </span>fi *<span class="st"> </span><span class="dv">2</span>
<span class="co">#logarithm of image where non-zero</span>
logfi &lt;-<span class="st"> </span><span class="kw">log</span>(fi[fi&gt;<span class="dv">0</span>])
expfi &lt;-<span class="st"> </span><span class="kw">exp</span>(fi[fi&gt;<span class="dv">0</span>])
divfi &lt;-<span class="st"> </span>sumfi /<span class="st"> </span>mulfi</code></pre></li>
</ul>
</div>
<div id="dilation-or-erosion-of-masks-and-images" class="section level2">
<h2>Dilation or erosion of masks and images</h2>
<p>The typical rule for dilation and erosion of images in ANTsR is minimum for erosion and maximum for dilation (ITK rules).</p>
<ul>
<li><p>Grayscale dilation of an image (compare it with binary dilation below):</p>
<pre class="sourceCode r"><code class="sourceCode r"><span class="co">#dilating by a radius of 3 voxels</span>
GDdilated &lt;-<span class="st"> </span><span class="kw">iMath</span>(fi,<span class="st">&quot;GD&quot;</span>, <span class="dv">3</span>)
<span class="co">#to see what dilation has done</span>
<span class="kw">invisible</span>(<span class="kw">plot</span>(GDdilated))
<span class="co">#&gt; Warning in rgl.init(initValue, onlyNULL): RGL: unable to open X11 display</span>
<span class="co">#&gt; Warning in fun(libname, pkgname): error in rgl_init</span></code></pre>
<p><img src="" /></p>
<pre class="sourceCode r"><code class="sourceCode r"><span class="co">#to see the difference a dilation can make</span>
<span class="kw">invisible</span>(<span class="kw">plot</span>(GDdilated -<span class="st"> </span>fi))</code></pre>
<p><img src="" /></p></li>
<li><p>Grayscale erosion of an image (compare it with binary erosion below).</p>
<pre class="sourceCode r"><code class="sourceCode r">erosion &lt;-<span class="st"> </span><span class="kw">iMath</span>(fi,<span class="st">&quot;GE&quot;</span>, <span class="dv">3</span>)
<span class="kw">invisible</span>(<span class="kw">plot</span>(erosion))</code></pre>
<p><img src="" /></p></li>
<li><p>Morphological dilation works on binary images, where it makes white regions bigger:</p>
<pre class="sourceCode r"><code class="sourceCode r">mask &lt;-<span class="st"> </span><span class="kw">getMask</span>(fi)
MD &lt;-<span class="st"> </span><span class="kw">iMath</span>(mask, <span class="st">&quot;MD&quot;</span>, <span class="dv">3</span>)
<span class="co">#to see the difference it made</span>
<span class="kw">invisible</span>(<span class="kw">plot</span>(MD -<span class="st"> </span>mask))</code></pre>
<p><img src="" /></p></li>
<li><p>Morphological erosion makes white regions of a binary mask smaller.</p>
<pre class="sourceCode r"><code class="sourceCode r">ME &lt;-<span class="st"> </span><span class="kw">iMath</span>(mask, <span class="st">&quot;ME&quot;</span>, <span class="dv">3</span>)
<span class="kw">invisible</span>(<span class="kw">plot</span>(ME))</code></pre>
<p><img src="" /></p></li>
</ul>
</div>
<div id="opening-and-closing-image-filters" class="section level2">
<h2>Opening and closing image filters</h2>
<ul>
<li>Morphological closing of a binary image: operation <code>MC</code> fill holes with the provided radius parameter, for example:</li>
</ul>
<pre class="sourceCode r"><code class="sourceCode r">newMask &lt;-<span class="st"> </span><span class="kw">iMath</span>(mask, <span class="st">&quot;MC&quot;</span>, <span class="dv">4</span>)
<span class="kw">invisible</span>(<span class="kw">plot</span>(newMask,<span class="dt">slices=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">1</span>)))</code></pre>
<p><img src="" /></p>
<ul>
<li>Morphological opening of a binary image: removes small structures at the boundary or interior of an image. Syntax is similar to the previous procedure with the operation <code>MO</code>.</li>
</ul>
</div>
<div id="padding-or-cropping-an-image" class="section level2">
<h2>Padding or cropping an image</h2>
<p><code>PadImage</code> is a function to add/remove voxels to/from images.</p>
<ul>
<li><p>Positive numbers will pad image in each direction. So for example using 2 will increase an image with 256 voxels to 260.</p>
<pre class="sourceCode r"><code class="sourceCode r">padded &lt;-<span class="st"> </span><span class="kw">iMath</span>(fi, <span class="st">&quot;PadImage&quot;</span>, <span class="dv">2</span>)
<span class="co">#compare padded image dimensions with the original dimensions</span>
<span class="kw">dim</span>(fi)
<span class="co">#&gt; [1] 256 256</span>
<span class="kw">dim</span>(padded)
<span class="co">#&gt; [1] 260 260</span></code></pre></li>
<li><p>Negative numbers will crop the image in each direciton. For example using -2 will convert a 2-dimensional image with 256 voxels in X and Y direction to 252 voxels in each dimension.</p>
<pre class="sourceCode r"><code class="sourceCode r">cropped &lt;-<span class="st"> </span><span class="kw">iMath</span>(fi, <span class="st">&quot;PadImage&quot;</span>, -<span class="dv">2</span>)
<span class="co">#compare cropped image with the original one</span>
<span class="kw">dim</span>(fi)
<span class="co">#&gt; [1] 256 256</span>
<span class="kw">dim</span>(cropped)
<span class="co">#&gt; [1] 252 252</span></code></pre></li>
</ul>
</div>
<div id="distance-map" class="section level2">
<h2>Distance map</h2>
<ul>
<li><p><code>MaurerDistance</code> calculates the Euclidean distance transform of a binary image in time linear with total number of voxels. It assumes that inside the binary image has negative distance, while outside of the binary mask has positve distance. Distance maps could be used for example, in shape analysis, skletonizing or path finding.</p>
<pre class="sourceCode r"><code class="sourceCode r">distanceMap &lt;-<span class="st"> </span><span class="kw">iMath</span>(mask, <span class="st">&quot;MaurerDistance&quot;</span>)
<span class="kw">invisible</span>(<span class="kw">plot</span>(distanceMap))</code></pre>
<p><img src="" /></p></li>
<li><p><code>D</code> implements ITK’s <code>DanielssonDistanceMap</code>. It calculates the Euclidean distance map, which shows at each voxel the shortest distance to the nearest voxel in the background (assuming that the input is a binary image).</p>
<pre class="sourceCode r"><code class="sourceCode r">distanceMap &lt;-<span class="st"> </span><span class="kw">iMath</span>(mask, <span class="st">&quot;D&quot;</span>)
<span class="kw">invisible</span>(<span class="kw">plot</span>(distanceMap))</code></pre>
<p><img src="" /></p></li>
</ul>
</div>
<div id="denoising-with-anisotropic-diffusion" class="section level2">
<h2>Denoising with anisotropic diffusion</h2>
<p>To reduce noise without changing important parts of an image in computer vision, Perona-Malik is a promising method. Perona-Malik method to reduce noise with anisotropic diffusion is accessible via <code>PeronaMalik</code> operation in <code>iMath</code>. It requires two parameters: 1) number of iterations, and 2) conductance.</p>
<pre class="sourceCode r"><code class="sourceCode r">denoised &lt;-<span class="st"> </span><span class="kw">iMath</span>(fi, <span class="st">&quot;PeronaMalik&quot;</span>, <span class="dv">10</span>, <span class="fl">0.5</span>)
<span class="kw">invisible</span>(<span class="kw">plot</span>(denoised))</code></pre>
<p><img src="" /></p>
<pre class="sourceCode r"><code class="sourceCode r"><span class="co"># to see what the filter has removed</span>
<span class="kw">invisible</span>(<span class="kw">plot</span>(fi -<span class="st"> </span>denoised))</code></pre>
<p><img src="" /></p>
</div>
<div id="magnitude-of-gradient-computation" class="section level2">
<h2>Magnitude of gradient computation</h2>
<p><code>Grad</code> operation in <code>iMath</code> calculates the gradient of the magnitude of an image by convolution with the first derivative of a Gaussian. Required parameters are: 1) sigma, and 2) normalize output (0 or 1, boolean).</p>
<pre class="sourceCode r"><code class="sourceCode r">  grad &lt;-<span class="st"> </span><span class="kw">iMath</span>(fi, <span class="st">&quot;Grad&quot;</span>, <span class="dv">1</span>)
  <span class="kw">invisible</span>(<span class="kw">plot</span>(grad))</code></pre>
<p><img src="" /></p>
</div>
<div id="laplacian-of-gaussian-of-an-image" class="section level2">
<h2>Laplacian of Gaussian of an image</h2>
<p><code>Laplacian</code> operation calculates the the Laplacian of Gaussian of an image by convolving with the second derivative of a Gaussian. <code>sigma</code> and <code>normalize</code> (0 or 1, boolean) are two required parameters.</p>
<pre class="sourceCode r"><code class="sourceCode r">  laplacianImage &lt;-<span class="st"> </span><span class="kw">iMath</span>(fi, <span class="st">&quot;Laplacian&quot;</span>, <span class="dv">1</span>, <span class="dv">1</span>)
  <span class="kw">invisible</span>(<span class="kw">plot</span>(laplacianImage))</code></pre>
<p><img src="" /></p>
</div>
<div id="sequential-operations-on-images" class="section level2">
<h2>Sequential operations on images</h2>
<p>Usually it is easier to perform sequential procedures starting from left to right, instead of right to left, as one needs with funcitons. This has been made possible by another package that <code>ANTsR</code> depends on, <code>magrittr</code>. For example, instead of:</p>
<pre class="sourceCode r"><code class="sourceCode r">fi&lt;-<span class="kw">antsImageRead</span>( <span class="kw">getANTsRData</span>(<span class="st">&quot;r16&quot;</span>) , <span class="dv">2</span> )
result &lt;-<span class="st"> </span><span class="kw">iMath</span>(<span class="kw">iMath</span>(fi, <span class="st">&quot;Laplacian&quot;</span>, <span class="dv">1</span>), <span class="st">&quot;GD&quot;</span>, <span class="dv">3</span>)</code></pre>
<p>One can do:</p>
<pre class="sourceCode r"><code class="sourceCode r"><span class="kw">require</span>(magrittr)
<span class="co">#&gt; Loading required package: magrittr</span>
result &lt;-<span class="st"> </span>fi %&gt;%<span class="st"> </span><span class="kw">iMath</span>(<span class="st">&quot;Laplacian&quot;</span>,<span class="dv">1</span>)  %&gt;%<span class="st"> </span><span class="kw">iMath</span>(<span class="st">&quot;GD&quot;</span>,<span class="dv">3</span>)</code></pre>
</div>
<div id="other-operations" class="section level2">
<h2>Other operations</h2>
<table>
<thead>
<tr class="header">
<th align="left">Operation</th>
<th align="center">Example</th>
<th align="right">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">FillHoles</td>
<td align="center"><code>img %&gt;% iMath(&quot;FillHoles&quot;)</code></td>
<td align="right">Fills holes in binary object</td>
</tr>
<tr class="even">
<td align="left">GetLargestComponent</td>
<td align="center"><code>img %&gt;% iMath(&quot;GetLargestComponent&quot;)</code></td>
<td align="right">Returns largest portion of binary object</td>
</tr>
<tr class="odd">
<td align="left">Neg</td>
<td align="center"><code>img %&gt;% iMath(&quot;Neg&quot;)</code></td>
<td align="right">Creates image negative</td>
</tr>
<tr class="even">
<td align="left">Normalize</td>
<td align="center"><code>img %&gt;% iMath(&quot;Normalize&quot;)</code></td>
<td align="right">Creates image negative</td>
</tr>
<tr class="odd">
<td align="left">TruncateImageIntensity</td>
<td align="center"><code>img %&gt;% iMath(&quot;TruncateImageIntensity&quot;, 0.05, 0.95)</code></td>
<td align="right">Trims intensities by quantiles</td>
</tr>
<tr class="even">
<td align="left">Sharpen</td>
<td align="center"><code>img %&gt;% iMath(&quot;Sharpen&quot;)</code></td>
<td align="right">Makes edges sharper</td>
</tr>
</tbody>
</table>
</div>
<div id="all-imath-operations" class="section level2">
<h2>All iMath operations</h2>
<table>
<caption>Valid iMath Operations</caption>
<thead>
<tr class="header">
<th align="left">Operation</th>
<th align="left">OperationType</th>
<th align="left">Parameters</th>
<th align="left">Example</th>
<th align="left">Description</th>
<th align="left">OutputDimensionalityChange</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">PadImage</td>
<td align="left">Basic</td>
<td align="left">positive or negative padvalue</td>
<td align="left">iMath(i,op,5)</td>
<td align="left">pads or de-pads image by n voxels on all sides</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">D</td>
<td align="left">Filter</td>
<td align="left">None</td>
<td align="left">iMath(i,op)</td>
<td align="left">distance transform</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">MaurerDistance</td>
<td align="left">Filter</td>
<td align="left">None</td>
<td align="left">iMath(i,op)</td>
<td align="left">distance transform</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">PeronaMalik</td>
<td align="left">Filter</td>
<td align="left">iterations, conductance</td>
<td align="left">iMath(i,op,10,0.5)</td>
<td align="left">perona malik edge preserving smoothing</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">Grad</td>
<td align="left">Filter</td>
<td align="left">sigma</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">gradient magnitude</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">Laplacian</td>
<td align="left">Filter</td>
<td align="left">sigma</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">laplacian of intensity</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">Canny</td>
<td align="left">Filter</td>
<td align="left">sigma</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">canny edge detector</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">BlobDetector</td>
<td align="left">Filter</td>
<td align="left">nblobs</td>
<td align="left">iMath(i,op,100)</td>
<td align="left">scale space blob detection-negate image to be positive blobs</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">MD</td>
<td align="left">Morphology</td>
<td align="left">element radius</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">dilation</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">ME</td>
<td align="left">Morphology</td>
<td align="left">element radius</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">erosion</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">MO</td>
<td align="left">Morphology</td>
<td align="left">element radius</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">opening</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">MC</td>
<td align="left">Morphology</td>
<td align="left">element radius</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">closing</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">GD</td>
<td align="left">Morphology</td>
<td align="left">element radius</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">grayscale dilation</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">GE</td>
<td align="left">Morphology</td>
<td align="left">element radius</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">grayscale erosion</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">GO</td>
<td align="left">Morphology</td>
<td align="left">element radius</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">grayscale opening</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">GC</td>
<td align="left">Morphology</td>
<td align="left">element radius</td>
<td align="left">iMath(i,op,1)</td>
<td align="left">grayscale closing</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">FillHoles</td>
<td align="left">LabelOp</td>
<td align="left">None</td>
<td align="left">iMath(i,op)</td>
<td align="left">fills holes in binary object</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">GetLargestComponent</td>
<td align="left">LabelOp</td>
<td align="left">None</td>
<td align="left">iMath(i,op)</td>
<td align="left">returns largest portion of binary object</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">LabelStats</td>
<td align="left">LabelOp</td>
<td align="left">roiImage</td>
<td align="left">iMath(i,op,roiImg)</td>
<td align="left">summarizes ROI values</td>
<td align="left">NA</td>
</tr>
<tr class="even">
<td align="left">Neg</td>
<td align="left">Intensity</td>
<td align="left">None</td>
<td align="left">iMath(i,op)</td>
<td align="left">create image negative</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">Normalize</td>
<td align="left">Intensity</td>
<td align="left">None</td>
<td align="left">iMath(i,op)</td>
<td align="left">normalize intensity into 0 1 range</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">TruncateImageIntensity</td>
<td align="left">Intensity</td>
<td align="left">lower and upper quantile</td>
<td align="left">iMath(i,op,0.05,0.95)</td>
<td align="left">trim intensities by quantiles</td>
<td align="left">0</td>
</tr>
<tr class="odd">
<td align="left">Sharpen</td>
<td align="left">Intensity</td>
<td align="left">None</td>
<td align="left">iMath(i,op)</td>
<td align="left">makes edges sharper</td>
<td align="left">0</td>
</tr>
<tr class="even">
<td align="left">ReflectionMatrix</td>
<td align="left">Transformation</td>
<td align="left">axis</td>
<td align="left">iMath(i,op,0)</td>
<td align="left">returns a reflection matrix itk transform in filename form</td>
<td align="left">NA</td>
</tr>
</tbody>
</table>
</div>



<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src  = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>

</body>
</html>
